//
//  MyViewController.m
//  Hxcsfw
//
//  Created by 企友软mac on 2017/10/25.
//  Copyright © 2017年 企友软mac. All rights reserved.
//

#import "MyViewController.h"
#import "MyListViewCell.h"
#import "WDXXViewController.h"
#import "ChangePsdViewController.h"
#import "WWebViewController.h"
#import "LoginViewController.h"
#import "WDKCViewController.h"
#import "ContactUsViewController.h"
#import "MyOrderViewController.h"
#import "MyScoringViewController.h"
#import "AccountViewController.h"
#import "JPUSHService.h"
#import "OurselvesViewController.h"
#import "MyHeadView.h"
#import "NetworkPayViewController.h"
#import "MemberViewController.h"
#import "CheckNetwork.h"

@interface MyViewController ()<UITableViewDataSource, UITableViewDelegate,MyHeadViewCellDelegate> {
    NSString *strHYJB;
}

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)MyHeadView *myHeadView;

@end

@implementation MyViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.navigationController.navigationBarHidden = YES;
    [WShareUtil setStatusBarBackgroundColor:WRGBColor(52, 88, 250)];
    [self.tableView reloadData];
//    if ([WShareUtil sharedData].dicSession) {
        [self requestWdjf];
//    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [WShareUtil setStatusBarBackgroundColor:WRGBColor(52, 88, 250)];

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
    [WShareUtil setStatusBarBackgroundColor:[UIColor clearColor]];
}

-(void)FPMPNOTICE{

    if ([[WShareUtil sharedData].dicSession[@"ismob"]intValue] == 0) {

        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"发票名片";
        NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"fpmp",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
        NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
        webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
        [self.navigationController pushViewController:webVc animated:NO];
        
    }else{
        [WShareUtil showAlert:@"温馨提示" message:@"此功能只对企业用户开放!"];
    }
}

-(void)WDKCNOTICE{
    WDKCViewController *wdkcVC = [[WDKCViewController alloc]init];
    wdkcVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:wdkcVC animated:NO];
}

-(void)WDWTNOTICE{
    
    WWebViewController *webVc = [[WWebViewController alloc] init];
    webVc.strTitle = @"我的问题";
    NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"wdwt",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
    NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
    webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
    [self.navigationController pushViewController:webVc animated:NO];
}

-(void)WDXXNOTICE{
    WWebViewController *webVc = [[WWebViewController alloc] init];
    
    NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"wdxx",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
    NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
    webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
    webVc.strTitle = @"我的消息";
    [self.navigationController pushViewController:webVc animated:NO];
    
}
-(void)WDDDNOTICE{
    MyOrderViewController *myOrderVc = [[MyOrderViewController alloc] init];
    myOrderVc.title = @"我的订单";
    [self.navigationController pushViewController:myOrderVc animated:NO];
}
-(void)FWYYNOTICE{
    WWebViewController *webVc = [[WWebViewController alloc] init];
    
    NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"fwyy",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
    NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
    webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
    webVc.strTitle = @"服务预约";
    [self.navigationController pushViewController:webVc animated:NO];
}

-(void)ZXYKNOTICE{
    
    NSString *isgjhy =[NSString stringWithFormat:@"%@",[WShareUtil sharedData].dicSession[@"isgjhy"]];
    if ([isgjhy isEqualToString:@"0"]) {//非高级会员
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"此功能只对高级会员开放!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [av show];
        return;
        
    }else {
        
        WWebViewController *webVc = [[WWebViewController alloc] init];
        
        NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"kcyy",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
        NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
        webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
        webVc.strTitle = @"在线约课";
        
        [self.navigationController pushViewController:webVc animated:NO];
    }
}

-(void)LogOutClick {

    [WShareUtil sharedData].dicSession = nil;
    [WShareUtil removeDataWithUserDefaultsForKey:@"USERNAME"];
    [WShareUtil removeDataWithUserDefaultsForKey:@"PASSWORD"];
    [WShareUtil removeDataWithUserDefaultsForKey:@"DICSESSION"];

    _myHeadView.loginView.hidden = NO;
    _myHeadView.logoutView.hidden = YES;
    [self.tableView reloadData];

    [self requestWdjf];
    
    [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
        WLog(@"%@",iAlias);
        
    } seq:10];
    
    NSSet *setTag = [[NSSet alloc] initWithObjects:@"register_soldier",nil];
    
    if ([WShareUtil sharedData].dicSession) {
        
        NSDictionary *dic = [WShareUtil sharedData].dicSession;
        NSString *k = [NSString stringWithFormat:@"%@",dic[@"gid"]];
        if ([k isEqualToString:@"0"]) {
            setTag = [[NSSet alloc] initWithObjects:@"register_soldier",nil];
        }else if([k isEqualToString:@"2"]){
            setTag = [[NSSet alloc] initWithObjects:@"common_soldier",nil];
        }else if ([k isEqualToString:@"3"]){
            setTag = [[NSSet alloc] initWithObjects:@"silver_soldier",nil];
        }else if ([k isEqualToString:@"4"]){
            setTag = [[NSSet alloc] initWithObjects:@"gold_soldier",nil];
        }
    }
    [JPUSHService deleteTags:setTag completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
        WLog(@"%@",iTags);
    } seq:11];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = YES;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FPMPNOTICE) name:@"FPMP" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WDKCNOTICE) name:@"WDKC" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WDWTNOTICE) name:@"WDWT" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WDXXNOTICE) name:@"WDXX" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WDDDNOTICE) name:@"WDDD" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FWYYNOTICE) name:@"FWYY" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ZXYKNOTICE) name:@"ZXYK" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(LogOutClick) name:@"LogOut" object:nil];

    _myHeadView = [[[NSBundle mainBundle] loadNibNamed:@"MyHeadView" owner:self options:nil] lastObject];
    _myHeadView.delegate = self;
    _myHeadView.lbLog.layer.cornerRadius = 6.;
    _myHeadView.lbLog.layer.borderColor = [UIColor whiteColor].CGColor;
    _myHeadView.lbLog.layer.borderWidth = 0.5;
    _myHeadView.layer.masksToBounds = YES;


    if ([WShareUtil sharedData].dicSession) {
        _myHeadView.loginView.hidden = YES;
        _myHeadView.logoutView.hidden = NO;
    } else {
        _myHeadView.loginView.hidden = NO;
        _myHeadView.logoutView.hidden = YES;
    }

    self.tableView.tableHeaderView = _myHeadView;
    [self.view addSubview:self.tableView];
    [self.tableView.superview insertSubview:[UIView new] atIndex:0];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessClick) name:@"LoginSuccess" object:nil];

//    if (@available(iOS 11, *)) {
//        [self setAdditionalSafeAreaInsets:self.view.safeAreaInsets];
//  }
}

- (void)loginSuccessClick{
    _myHeadView.loginView.hidden = YES;
    _myHeadView.logoutView.hidden = NO;
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, WSCREENH_WIDTH, WSCREENH_HEIGHT - 49 - 20) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.bounces = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0) {
        return 5;
    } else if (section == 1) {
        if ([WShareUtil sharedData].dicSession) {
            return 3;
        } else {
            return 1;
        }
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 54;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, 44)];
    headerView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];

    UILabel *lbTit = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 44)];
    lbTit.textColor = WRGBColor(150, 151, 152);
    lbTit.font = [UIFont systemFontOfSize:16];
    if (section == 0) {
        lbTit.text = @"我的服务";
    }else if (section == 1){
        lbTit.text = @"其他";
    }

    [headerView addSubview:lbTit];

    return headerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HOTCELL"];

    if (indexPath.section == 0){
        if (cell == nil) {
            MyListViewCell *listViewCell = [[[NSBundle mainBundle]loadNibNamed:@"MyListViewCell" owner:self options:nil]lastObject];
            listViewCell.lbAccount.hidden = YES;
            if (indexPath.row == 0) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_coin@2x.png"];
                listViewCell.lbTitle.text = @"账户余额";
                listViewCell.lbAccount.hidden = NO;

                if ([WShareUtil strNilOrEmpty:[WShareUtil sharedData].strRemaining]) {
                    listViewCell.lbAccount.text = @"￥0.00";
                } else {
                    listViewCell.lbAccount.text = [NSString stringWithFormat:@"￥%.2f",[[WShareUtil sharedData].strRemaining floatValue]];
                }
            }else if (indexPath.row == 1) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_message@2x.png"];
                listViewCell.lbTitle.text = @"我的消息";
            }else if (indexPath.row == 2) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_order@2x.png"];
                listViewCell.lbTitle.text = @"我的订单";
            }else if (indexPath.row == 3) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_online@2x.png"];
                listViewCell.lbTitle.text = @"在线约课";
            }else if (indexPath.row == 4) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_pay@2x.png"];
                listViewCell.lbTitle.text = @"会员缴费";
            }
//            else if (indexPath.row == 5) {
//                listViewCell.imgHead.image = [UIImage imageNamed:@"my_phone@2x.png"];
//                listViewCell.lbTitle.text = @"联系我们";
//            }
//            else if (indexPath.row == 5) {
//                listViewCell.imgHead.image = [UIImage imageNamed:@"my_our@2x.png"];
//                if ([WShareUtil sharedData].dicSession) {
//                    listViewCell.lbTitle.text = @"我的账户";
//                } else {
//                    listViewCell.lbTitle.text = @"账户余额";
//                }
//            }
            listViewCell.imgArrow.image = [UIImage imageNamed:@"my_arrow@2x.png"];

            cell = listViewCell;
        }
    }else if (indexPath.section == 1){
        if (cell == nil) {
            MyListViewCell *listViewCell = [[[NSBundle mainBundle]loadNibNamed:@"MyListViewCell" owner:self options:nil]lastObject];
            listViewCell.lbAccount.hidden = YES;

            if (indexPath.row == 0) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_our@2x.png"];
                listViewCell.lbTitle.text = @"关于我们";
            } else if (indexPath.row == 1) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_password@2x.png"];
                listViewCell.lbTitle.text = @"修改密码";
            }else if (indexPath.row == 2) {
                listViewCell.imgHead.image = [UIImage imageNamed:@"my_logout@2x.png"];
                listViewCell.lbTitle.text = @"退出登录";
            }
            listViewCell.imgArrow.image = [UIImage imageNamed:@"my_arrow@2x.png"];

            cell = listViewCell;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.section == 0) {

        if (indexPath.row == 0) {
            AccountViewController *accountVc = [[AccountViewController alloc] init];
            [self.navigationController pushViewController:accountVc animated:YES];
            return;
        }else if (indexPath.row == 4) {

            CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
            if (![checkNetwork isNetworkReachable]) {//没网
                return;
            } else {
                if ([WShareUtil strNilOrEmpty:strHYJB]) {
                    MemberViewController *memberVc = [[MemberViewController alloc] init];
                    memberVc.title = @"会员缴费";
                    [self.navigationController pushViewController:memberVc animated:YES];
                    return;
                } else {
                    NSString *message = [NSString stringWithFormat:@"您已经是%@",strHYJB];
                    [WShareUtil showAlert:ALERT_TITLE message:message];
                    return;
                }
            }
            
        }
//        else if (indexPath.row == 4) {
//            ContactUsViewController *contactUsVc = [[ContactUsViewController alloc] init];
//            [self.navigationController pushViewController:contactUsVc animated:YES];
//            return;
//        }

//        if (indexPath.row == 5) {
//            AccountViewController *accountVc = [[AccountViewController alloc] init];
//            [self.navigationController pushViewController:accountVc animated:YES];
//            return;
//        }

        if ([WShareUtil sharedData].dicSession) {

            if (indexPath.row == 1) {
                WWebViewController *webVc = [[WWebViewController alloc] init];

                NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"wdxx",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
                NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
                webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
                webVc.strTitle = @"我的消息";
                [self.navigationController pushViewController:webVc animated:YES];

            }else if (indexPath.row == 2) {

                CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
                if (![checkNetwork isNetworkReachable]) {//没网
                    return;
                } else {
                    MyOrderViewController *myOrderVc = [[MyOrderViewController alloc] init];
                    myOrderVc.title = @"我的订单";
                    [self.navigationController pushViewController:myOrderVc animated:YES];
                }
                
            }else if (indexPath.row == 3) {
                
                NSString *isgjhy =[NSString stringWithFormat:@"%@",[WShareUtil sharedData].dicSession[@"isgjhy"]];
                if ([isgjhy isEqualToString:@"0"]) {//非高级会员
                    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"此功能只对高级会员开放!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                    [av show];
                    return;
                    
                }else {
                    
                    WWebViewController *webVc = [[WWebViewController alloc] init];

                    NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"kcyy",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
                    NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
                    webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
                    webVc.strTitle = @"在线约课";

                    [self.navigationController pushViewController:webVc animated:YES];
                }
            }
        } else {
//            [SVProgressHUD showImage:nil status:@"请先登录"];
//            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
//            [SVProgressHUD dismissWithDelay:1.];
//            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];   //背景颜色
            if (indexPath.row == 1) {
                [WShareUtil sharedData].Who = @"WDXX";
            }else if (indexPath.row == 2) {
                [WShareUtil sharedData].Who = @"WDDD";
            }
//            else if (indexPath.row == 3) {
//                [WShareUtil sharedData].Who = @"FWYY";
//            }
            else if (indexPath.row == 3) {
                [WShareUtil sharedData].Who = @"ZXYK";
            }
            LoginViewController *loginVc = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }

    } else if (indexPath.section == 1) {

        if (indexPath.row == 0) {
            //关于我们
            OurselvesViewController *ourselvesVc = [[OurselvesViewController alloc]init];
            ourselvesVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:ourselvesVc animated:YES];
        } else if (indexPath.row == 1) {
            //我的消息
            //修改密码
            ChangePsdViewController *cpsdViewController = [[ChangePsdViewController alloc]init];
            cpsdViewController.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:cpsdViewController animated:YES];
        }else if (indexPath.row == 2) {
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"确定要退出登录吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alertView.tag = 55;
            [alertView show];
        }
    }

    //    //我的问题
    //    WDWTViewController *wdwtVC = [[WDWTViewController alloc]init];
    //    wdwtVC.hidesBottomBarWhenPushed = YES;
    //    [self.navigationController pushViewController:wdwtVC animated:YES];

    //    //我的课程
    //    WDKCViewController *wdkcVC = [[WDKCViewController alloc]init];
    //    wdkcVC.hidesBottomBarWhenPushed = YES;
    //    [self.navigationController pushViewController:wdkcVC animated:YES];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (alertView.tag == 55) {
        if (buttonIndex == 1) {
            [WShareUtil sharedData].dicSession = nil;
            [WShareUtil removeDataWithUserDefaultsForKey:@"USERNAME"];
            [WShareUtil removeDataWithUserDefaultsForKey:@"PASSWORD"];
            [WShareUtil removeDataWithUserDefaultsForKey:@"DICSESSION"];
            strHYJB = @"";

            [[NSNotificationCenter defaultCenter] postNotificationName:@"LogoutSucceed" object:nil];//修改成功退出登录的通知
            [self requestWdjf];

            _myHeadView.loginView.hidden = NO;
            _myHeadView.logoutView.hidden = YES;
            [self.tableView reloadData];

            [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
                WLog(@"%@",iAlias);

            } seq:10];

            NSSet *setTag = [[NSSet alloc] initWithObjects:@"register_soldier",nil];

            if ([WShareUtil sharedData].dicSession) {

                NSDictionary *dic = [WShareUtil sharedData].dicSession;
                NSString *k = [NSString stringWithFormat:@"%@",dic[@"gid"]];
                if ([k isEqualToString:@"0"]) {
                    setTag = [[NSSet alloc] initWithObjects:@"register_soldier",nil];
                }else if([k isEqualToString:@"2"]){
                    setTag = [[NSSet alloc] initWithObjects:@"common_soldier",nil];
                }else if ([k isEqualToString:@"3"]){
                    setTag = [[NSSet alloc] initWithObjects:@"silver_soldier",nil];
                }else if ([k isEqualToString:@"4"]){
                    setTag = [[NSSet alloc] initWithObjects:@"gold_soldier",nil];
                }
            }
            [JPUSHService deleteTags:setTag completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
                WLog(@"%@",iTags);
            } seq:11];
        }
    }
}

- (void) delegatMyHeadBtnClick:(UIButton *)sender{

    if (sender.tag == 1000) {
        LoginViewController *loginVc = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:loginVc animated:YES];
    } else if (sender.tag == 1001) {
        MyScoringViewController *myScoreVc = [[MyScoringViewController alloc] init];
        myScoreVc.title = @"我的积分";
        myScoreVc.strName = _myHeadView.lbNsrmc.text;
        myScoreVc.strAcpoint = _myHeadView.lbAcpoint.text;
        myScoreVc.strCopoint = _myHeadView.lbCopiont.text;
        [self.navigationController pushViewController:myScoreVc animated:YES];
    } else if (sender.tag == 2000) {//发票名片
        
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"发票名片";
        if ([WShareUtil sharedData].dicSession) {
            
            if ([[WShareUtil sharedData].dicSession[@"ismob"]intValue] == 0) {
                NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"fpmp",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
                NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
                webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
                [self.navigationController pushViewController:webVc animated:YES];
            }else{
                [WShareUtil showAlert:@"温馨提示" message:@"此功能只对企业用户开放!"];
            }

        } else {
//            webVc.strUrl = @"https://jskp.jss.com.cn/Contents/pages/jskpCard/index.html";
//            [SVProgressHUD showImage:nil status:@"请先登录"];
//            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
//            [SVProgressHUD dismissWithDelay:1.];
//            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];   //背景颜色
            
            [WShareUtil sharedData].Who = @"FPMP";
            LoginViewController *loginVc = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }
        
    } else if (sender.tag == 2001) {//我的课程

        if ([WShareUtil sharedData].dicSession) {
            
            CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
            if (![checkNetwork isNetworkReachable]) {//没网
                return;
            } else {
                
                WDKCViewController *wdkcVC = [[WDKCViewController alloc]init];
                wdkcVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:wdkcVC animated:YES];
                
            }
        } else {
            //            [SVProgressHUD showImage:nil status:@"请先登录"];
            //            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
            //            [SVProgressHUD dismissWithDelay:1.];
            //            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];   //背景颜色
            
            [WShareUtil sharedData].Who = @"WDKC";
            LoginViewController *loginVc = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }
        
    } else {//我的问题

        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"我的问题";
        if ([WShareUtil sharedData].dicSession) {

            NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"wdwt",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
            NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
            webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
            [self.navigationController pushViewController:webVc animated:YES];

        } else {
//            [SVProgressHUD showImage:nil status:@"请先登录"];
//            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
//            [SVProgressHUD dismissWithDelay:1.];
//            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];   //背景颜色
            
            [WShareUtil sharedData].Who = @"WDWT";
            LoginViewController *loginVc = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }
    }
}

- (void)requestWdjf{

    NSDictionary *parametersDict;
    NSString *nologinuser;
    if ([WShareUtil sharedData].dicSession) {
        parametersDict = @{@"content":@{@"revert":@"basic",@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]},@"mode":@"native",@"service":@"mine"};
    } else {
        nologinuser = [WShareUtil getUUID];
        parametersDict = @{@"content":@{@"revert":@"basic",@"nologinuser":nologinuser},@"mode":@"native",@"service":@"mine"};
    }
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        WLog(@"------%@",responseObject);
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];

        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        if ([successStr isEqualToString:@"false"]) {
            [WShareUtil sharedData].strRemaining = @"0.0";
            [WShareUtil sharedData].strlxmc = @"";
            return;
        }

        [WShareUtil sharedData].strRemaining = returnDic[@"remaining"];
        [WShareUtil sharedData].strlxmc = returnDic[@"lxmc"];

        NSString *strJbmc = returnDic[@"lxmc"];
        if ([strJbmc rangeOfString:@"会员"].location != NSNotFound) {
            strJbmc = [strJbmc stringByReplacingOccurrencesOfString:@"会员" withString:@""];
        }else if ([strJbmc isEqualToString:@"金卡"]) {
            strJbmc = [NSString stringWithFormat:@"%@会员",strJbmc];
        }

        if ([WShareUtil sharedData].dicSession) {
            _myHeadView.lbCopiont.text = returnDic[@"copoint"];
            _myHeadView.lbAcpoint.text = returnDic[@"acpiont"];
            if ([WShareUtil strNilOrEmpty:returnDic[@"nsrmc"]]) {
                _myHeadView.lbNsrmc.text = returnDic[@"nsrsbh"];
            }else{
                _myHeadView.lbNsrmc.text = returnDic[@"nsrmc"];
            }
            if ([WShareUtil strNilOrEmpty:returnDic[@"lxmc"]] && [WShareUtil strNilOrEmpty:returnDic[@"kxkcs"]]) {
                _myHeadView.lbMember.hidden = YES;
                _myHeadView.lbNoMember.hidden = NO;
                _myHeadView.imgMember.hidden = YES;
                _myHeadView.lbSelect.hidden = YES;
                _myHeadView.lbSelectNum.hidden = YES;
                _myHeadView.lbNoChosen.hidden = YES;
                strHYJB = @"";
            } if ([WShareUtil strNilOrEmpty:returnDic[@"lxmc"]] && returnDic[@"kxkcs"] >= 0) {
                _myHeadView.lbMember.hidden = YES;
                _myHeadView.lbNoMember.hidden = NO;
                _myHeadView.imgMember.hidden = YES;
                _myHeadView.lbSelect.hidden = NO;
                _myHeadView.lbSelectNum.hidden = NO;
                _myHeadView.lbNoChosen.hidden = YES;
                strHYJB = @"";
                _myHeadView.lbSelectNum.text = [NSString stringWithFormat:@"%@门",returnDic[@"kxkcs"]];
            } else {
                _myHeadView.lbMember.hidden = NO;
                _myHeadView.lbNoMember.hidden = YES;
                _myHeadView.lbMember.text = strJbmc;
                strHYJB = returnDic[@"lxmc"];
                _myHeadView.imgMember.hidden = NO;
                if ([returnDic[@"kxkcs"] isEqualToString:@"0"] && ![strJbmc isEqualToString:@"学习卡C"]) {
                    _myHeadView.lbSelect.hidden = NO;
                    _myHeadView.lbSelectNum.hidden = NO;
                    _myHeadView.lbNoChosen.hidden = YES;
                    _myHeadView.lbSelectNum.text = [NSString stringWithFormat:@"%@门",returnDic[@"kxkcs"]];
                } else if ([WShareUtil strNilOrEmpty:returnDic[@"kxkcs"]]){
                    _myHeadView.lbSelect.hidden = YES;
                    _myHeadView.lbSelectNum.hidden = YES;
                    _myHeadView.lbNoChosen.hidden = YES;
                } else if ([strJbmc isEqualToString:@"学习卡C"] && [returnDic[@"kxkcs"] isEqualToString:@"0"]){
                    _myHeadView.lbSelect.hidden = YES;
                    _myHeadView.lbSelectNum.hidden = YES;
                    _myHeadView.lbNoChosen.hidden = YES;

                } else {
                    _myHeadView.lbSelect.hidden = NO;
                    _myHeadView.lbSelectNum.hidden = NO;
                    _myHeadView.lbNoChosen.hidden = YES;

                    if ([returnDic[@"kxkcs"] isEqualToString:@"-1"]) {
                        _myHeadView.lbSelectNum.text = @"不限";
                    } else {
                        _myHeadView.lbSelectNum.text = [NSString stringWithFormat:@"%@门",returnDic[@"kxkcs"]];
                    }
                }
            }
        } else {
            _myHeadView.lbYCopiont.text = returnDic[@"copoint"];
            _myHeadView.lbYAcpoint.text = returnDic[@"acpiont"];
            if ([WShareUtil strNilOrEmpty:returnDic[@"lxmc"]]) {
                _myHeadView.lbYMember.hidden = YES;
                _myHeadView.lbYNoMember.hidden = NO;
                _myHeadView.imgYMember.hidden = YES;
                _myHeadView.lbYSelect.hidden = YES;
                _myHeadView.lbYSelectNum.hidden = YES;
                strHYJB = @"";
            } else {
                _myHeadView.lbYMember.hidden = NO;
                _myHeadView.lbYNoMember.hidden = YES;
                _myHeadView.lbYMember.text = strJbmc ;
                strHYJB = returnDic[@"lxmc"];
                _myHeadView.imgYMember.hidden = NO;
                _myHeadView.lbYSelect.hidden = NO;
                _myHeadView.lbYSelectNum.hidden = NO;
                if ([WShareUtil strNilOrEmpty:returnDic[@"kxkcs"]]) {
                    _myHeadView.lbYSelect.hidden = YES;
                    _myHeadView.lbYSelectNum.hidden = YES;
                    _myHeadView.lbYNoChosen.hidden = YES;
                }else if ([returnDic[@"kxkcs"] isEqualToString:@"0"] && ![strJbmc isEqualToString:@"学习卡C"]) {
                    _myHeadView.lbYSelect.hidden = NO;
                    _myHeadView.lbYSelectNum.hidden = NO;
                    _myHeadView.lbYNoChosen.hidden = YES;
                    _myHeadView.lbYSelectNum.text = [NSString stringWithFormat:@"%@门",returnDic[@"kxkcs"]];
                }else if ([strJbmc isEqualToString:@"学习卡C"] && [returnDic[@"kxkcs"] isEqualToString:@"0"]){
                    _myHeadView.lbYSelect.hidden = YES;
                    _myHeadView.lbYSelectNum.hidden = YES;
                    _myHeadView.lbYNoChosen.hidden = YES;

                } else {
                    _myHeadView.lbYSelect.hidden = NO;
                    _myHeadView.lbYSelectNum.hidden = NO;
                    _myHeadView.lbYNoChosen.hidden = YES;

                    if ([returnDic[@"kxkcs"] isEqualToString:@"-1"]) {
                        _myHeadView.lbYSelectNum.text = @"不限";
                    } else {
                        _myHeadView.lbYSelectNum.text = [NSString stringWithFormat:@"%@门",returnDic[@"kxkcs"]];
                    }
                }
            }
        }
        [self.tableView reloadData];

    } failure:^(NSError *error) {
        WLog(@"失败");
    } showProgress:YES];
}

-(void)dealloc{
    //移除所有通知监控
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end


